package at.sysarch.bean;

import javax.media.jai.operator.MedianFilterDescriptor;
import javax.media.jai.operator.MedianFilterShape;

import at.pimpmypipe.interfaces.Readable;
import at.sysarch.domain.TransferImage;
import at.sysarch.filter.MedianFilter;
import at.sysarch.utils.LinkEvent;
import at.sysarch.utils.LinkListener;

public class Median extends AbstractBean<MedianFilter> implements LinkListener {

	private static final long serialVersionUID = 1L;

	public Median() {
		_filter = new MedianFilter(this);
	}
	
	@Override
	public void linkBean(LinkEvent event) {
		_filter.setInput(event.getInput());
		event.getInput().setOutput(_filter);
		_filter.run();
	}

	@Override
	public void addLinkListener(LinkListener listener) {
		listener.linkBean(new LinkEvent((Readable<TransferImage>)_filter));
	}

	@Override
	public void removeLinkListener(LinkListener listener) {	
		
	}
	
	public void setMaskSize(int maskSize) {
		
		_filter.setMaskSize(maskSize);
	}
	
	public int getMaskSize() {
		return _filter.getMaskSize();
	}
	
	public void setMaskShape(String maskShape) {
		
		MedianFilterShape shape = null;
		
		if (maskShape.equals(MedianFilterDescriptor.MEDIAN_MASK_PLUS.getName())) {
			shape = MedianFilterDescriptor.MEDIAN_MASK_PLUS;
		}
		else if (maskShape.equals(MedianFilterDescriptor.MEDIAN_MASK_SQUARE.getName())) {
			shape = MedianFilterDescriptor.MEDIAN_MASK_SQUARE;
		}
		else if (maskShape.equals(MedianFilterDescriptor.MEDIAN_MASK_SQUARE_SEPARABLE.getName())) {
			shape = MedianFilterDescriptor.MEDIAN_MASK_SQUARE_SEPARABLE;
		}
		else if (maskShape.equals(MedianFilterDescriptor.MEDIAN_MASK_X.getName())) {
			shape = MedianFilterDescriptor.MEDIAN_MASK_X;
		}
		_filter.setMaskShape(shape);
	}
	
	public String getMaskShape() {
		
		return _filter.getMaskShape().getName();
	}
}
